import { PureComponent } from 'react';
import moment from 'moment';
import '@/assets/iconfont/iconfont';
import styles from './StaffInfoList.less';
import SelectDeptTree from '@/components/SelectDeptTree';
import { dicTextByCodePcode,dicListByPcode } from '@/utils/dictionary'
import {
    Row,
    Col,
    Form,
    Input,
    Select,
    Modal,
    DatePicker,
    Button,
    Upload,
    Cascader
} from 'antd';
const FormItem = Form.Item;
const { Option } = Select;
const formItemLayout = {
 	labelCol: { span: 10 },
   	wrapperCol: { span: 14 },
};

@Form.create()
class UpdateForm extends PureComponent {

	constructor(props) {
		super(props);
		// const staffAge = moment().format('YYYY') - moment(props.values.date_of_birth).format('YYYY');
    this.state = {
			formVals: {
        za0100: props.values.za0100,
        id: props.values.id,
        a0501_1: props.values.a0501_1,
        a0501_2: props.values.a0501_2,
        zc9993: props.values.zc9993,
        a0304: props.values.a0304,
        a0501_3: props.values.a0501_3,
        a0504: props.values.a0504,
        a0507: props.values.a0507,
        a0511: props.values.a0511,
        a0514: props.values.a0514,
        a0517: props.values.a0517,
        a0521: props.values.a0521,
        a0524: props.values.a0524,
        a0527: props.values.a0527,
        a0531: props.values.a0531,
        a0534: props.values.a0534,
        a0537: props.values.a0537,
        a0541: props.values.a0541,
        a0544: props.values.a0544,
        a0545: props.values.a0545,
        a0547: props.values.a0547,
        a0549: props.values.a0549,
        a0551: props.values.a0551,
        a0554: props.values.a0554,
        a0557: props.values.a0557,
        a0561: props.values.a0561,
        a0564: props.values.a0564,
        a0565: props.values.a0565,
        a0567: props.values.a0567,
        a0568: props.values.a0568

			},
			getDeptTreeBySelectTree: "",
		};

	}


	componentWillReceiveProps(nextProps) {
		// if(undefined != nextProps.values && nextProps.values !== this.props.values) {
		// 	const staffAge = moment().format('YYYY') - moment(nextProps.values.date_of_birth).format('YYYY');
		//     this.setState({
		//       formVals: nextProps.values,
		//       imageUrl: nextProps.values.photo_sign,
		//       photoNum: nextProps.values.photo_sign?1:0,
		//       ageNum: staffAge?staffAge:null
		//     });
		// }

	}

	selectedDeptTreeValue = (deptRecord) => {
		this.setState({
			getDeptTreeBySelectTree: deptRecord
		})
	}



 	birthChange = value => {
		this.setState({
			ageNum: moment().format('YYYY') - value.format('YYYY')

		})
	}

	handleLocalUpdate = (event) => {
		event.preventDefault();
		const { form,handleSubmitSubsetInfo } = this.props;
		const { formVals: oldValue,getDeptTreeBySelectTree } = this.state;
		form.validateFields((err, fieldsValue) => {
			if(err) return;
			form.resetFields();
			const formVals = {
				...oldValue,
				...fieldsValue
			};
			this.setState({
				formVals,
			});

			/* if(getDeptTreeBySelectTree) {
				formVals.dept_id = getDeptTreeBySelectTree.triggerNode.props.dataRef.dept_id;
				formVals.dept = getDeptTreeBySelectTree.triggerNode.props.dataRef.title;
			}

			if(formVals.post) {
				formVals.post_id = formVals.post.key;
				formVals.post_name = formVals.post.label;
			}*/

			if(formVals.a0561) {
      			formVals.a0561 = moment(formVals.a0561._d).format("YYYY-MM-DD");
      		}
			if(formVals.a0557) {
      			formVals.a0557 = moment(formVals.a0557._d).format("YYYY-MM-DD");
      		}
      if(formVals.a0544) {
      			formVals.a0544 = moment(formVals.a0544._d).format("YYYY-MM-DD");
      		}
			// formVals.file = this.state.file; 
			handleSubmitSubsetInfo(formVals,"update_for_staff_pATJobInfo");

		});
	};

  render() {
    const {
    	form: {getFieldDecorator},
    	falg,
      spinIndex,
    	cancelEditJobInfo,
    	cascaderList,
    	values,
    	selectDeptTree,
    	postForUser,
      requestModelName,
      dispatch
    } = this.props;

    const parentDeptTreeMethod = {
		dispatch: dispatch,
		selectDeptTree: selectDeptTree,
		selectedDeptTreeValue: this.selectedDeptTreeValue,
		requestModelName: requestModelName,
	}

    const { formVals,imageUrl,photoNum } = this.state;
    // 多选处理 TODO
    let newPlace = [];
    if(values.place_of_origin && values.place_of_origin != "null" ) {
    	const place = JSON.parse(values.place_of_origin);
    	newPlace = place.map((item,index) => item = item + '');
    }
	return (
		<div>
			{falg?(
				<Form  onSubmit={this.handleLocalUpdate}>

          {/* 任职信息*/}
			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

			        <Col md={12} sm={24}>
			          <FormItem  label="专业技术职务名称">
			              {getFieldDecorator('a0524', {
			              rules: [{ required: true, message: '请选择'}],
			              initialValue: formVals.a0524,
			              })(
                      <Select labelInValue placeholder="请选择" style={{ width: '100%' }}>
			              		{dicListByPcode('AE') != undefined?dicListByPcode('AE').map((item,index) => {
			              			return <Option value={item.DICTVALUE}>{item.DESCRIPTION}</Option>
			              		}):null}
			              	</Select>
                    )}
			          </FormItem>
			        </Col>

              <Col md={12} sm={24}>
                <FormItem  label="任职方式">
                    {getFieldDecorator('a0547', {
                      rules: [{ required: true, message: '请选择'}],
                      initialValue: formVals.a0547,
                    })(
                      <Select labelInValue placeholder="请选择" style={{ width: '100%' }}>
                      	{dicListByPcode('AE') != undefined?dicListByPcode('AE').map((item,index) => {
                      		return <Option value={item.DICTVALUE}>{item.DESCRIPTION}</Option>
                      	}):null}
                      </Select>
                    )}
                </FormItem>
              </Col>

			    </Row>
			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

			        <Col md={12} sm={24}>
			          <FormItem  label="任职状态">
			              {getFieldDecorator('a0554',{
			              	initialValue: formVals.a0554,
			              })(
			              	<Select labelInValue placeholder="请选择" style={{ width: '100%' }}>
			              		{dicListByPcode('AE') != undefined?dicListByPcode('AE').map((item,index) => {
			              			return <Option value={item.DICTVALUE}>{item.DESCRIPTION}</Option>
			              		}):null}
			              	</Select>
			              )}
			          </FormItem>
			        </Col>
			        <Col md={12} sm={24}>
			          <FormItem  label="专业技术岗位等级">
			              {getFieldDecorator('a0568', {
			              rules: [{ required: false, message: '请选择'}],
			              initialValue: formVals.a0568,
			              })(
                      <Select labelInValue placeholder="请选择" style={{ width: '100%' }}>
                        {dicListByPcode('AE') != undefined?dicListByPcode('AE').map((item,index) => {
                          return <Option value={item.DICTVALUE}>{item.DESCRIPTION}</Option>
                        }):null}
                      </Select>
                    )}
			          </FormItem>
			        </Col>

			    </Row>

			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

					<Col md={12} sm={24}>
			          <FormItem  label="任职变动类别">
			              {getFieldDecorator('a0551', {
			              rules: [{ required: false, message: '请选择'}],
			              initialValue: formVals.a0551,
			              })(
			              	<Select labelInValue placeholder="请选择" style={{ width: '100%' }}>
			              	  	{dicListByPcode('YT') != undefined?dicListByPcode('YT').map((item,index) => {
			              	  		return <Option value={item.DICTVALUE}>{item.DESCRIPTION}</Option>
			              	  	}):null}
			              	  </Select>
			              )}
			          </FormItem>
			        </Col>

			        <Col md={12} sm={24}>
			          <FormItem  label="任职起始日期">
			              {getFieldDecorator('a0544',{
			                rules: [{ required: false, message: '请选择！'}],
                      initialValue: formVals.a0544?moment(formVals.a0544):null,
                    })(
                      <DatePicker  format="YYYY-MM-DD" style={{ width: '100%' }} placeholder="请选择"/>
                    )}
			          </FormItem>
			        </Col>

			    </Row>

			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>


			        <Col md={12} sm={24}>
			          <FormItem  label="多职务主次序号">
			              {getFieldDecorator('a0527', {
			              rules: [{ required: false, message: '请选择'}],
			              initialValue: formVals.a0527,
			              })(
                      <Input placeholder="1-40个字符" />
                    )}
			          </FormItem>
			        </Col>
			        <Col md={12} sm={24}>
			          <FormItem  label="集体内排列顺序">
			              {getFieldDecorator('a0531', {
                    rules: [{ required: false, message: '1-40个字符'}],
			              initialValue: formVals.a0531,
			              })(<Input placeholder="1-40个字符" />)}
			          </FormItem>
			        </Col>

			    </Row>

			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>


			        <Col md={12} sm={24}>
			          <FormItem  label="主管工作">
			              {getFieldDecorator('a0534', {
			              rules: [{ required: false, message: '1-40个字符' }],
			              initialValue: formVals.a0534,
                    })(<Input placeholder="1-40个字符" />)}
			          </FormItem>
			        </Col>

			       	<Col  md={12} sm={24}>
			       	  <FormItem  label="批准文件名称或文号">
			       	      {getFieldDecorator('a0545', {
			       	        rules: [{ required: false, message: '1-40个字符'}],
                      initialValue: formVals.a0545,
			       	        })(<Input placeholder="1-40个字符" />)}
			       	  </FormItem>
			       	</Col>

			    </Row>
			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

			    	<Col md={12} sm={24}>
			    	  <FormItem  label="聘任证书编号">
			    	      {getFieldDecorator('a0549', {
			    	        rules: [{ required: false, message: '1-40个字符'}],
                    initialValue: formVals.a0314,
			    	        })(
			    	        <Input placeholder="1-40个字符" />
			    	      )}
			    	  </FormItem>
			    	</Col>

            <Col md={12} sm={24}>
              <FormItem  label="任职预定截止日期">
                  {getFieldDecorator('a0557', {
                    rules: [{ required: false, message: '请选择'}],
                    initialValue: formVals.a0557?moment(formVals.a0557):null,
                    })(
                      <DatePicker  format="YYYY-MM-DD" style={{ width: '100%' }} placeholder="请选择"/>
                    )}
              </FormItem>
            </Col>
			    </Row>

          {/* 任职机构信息*/}
          <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

			    	<Col md={12} sm={24}>
			    	  <FormItem  label="名称">
			    	      {getFieldDecorator('a0501_1', {
			    	        rules: [{ required: false, message: '1-40个字符'}],
                    initialValue: formVals.a0501_1,
			    	        })(
			    	        <Input placeholder="1-40个字符" />
			    	      )}
			    	  </FormItem>
			    	</Col>

            <Col md={12} sm={24}>
              <FormItem  label="代码">
                  {getFieldDecorator('a0501_2', {
                    rules: [{ required: false, message: '1-40个字符'}],
                    initialValue: formVals.a0501_2,
                    })(
                    <Input placeholder="1-40个字符" />
                  )}
              </FormItem>
            </Col>
			    </Row>

          <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

          	<Col md={12} sm={24}>
          	  <FormItem  label="所在政区">
          	      {getFieldDecorator('a0504', {
          	        rules: [{ required: false, message: '请选择'}],
                    initialValue: formVals.a0504,
          	        })(
                      <Select labelInValue placeholder="请选择" style={{ width: '100%' }}>
                        {dicListByPcode('AE') != undefined?dicListByPcode('AE').map((item,index) => {
                          return <Option value={item.DICTVALUE}>{item.DESCRIPTION}</Option>
                        }):null}
                      </Select>
          	      )}
          	  </FormItem>
          	</Col>

            <Col md={12} sm={24}>
              <FormItem  label="隶属关系">
                  {getFieldDecorator('a0507', {
                    rules: [{ required: false, message: '请选择'}],
                    initialValue: formVals.a0507,
                    })(
                      <Select labelInValue placeholder="请选择" style={{ width: '100%' }}>
                        {dicListByPcode('AE') != undefined?dicListByPcode('AE').map((item,index) => {
                          return <Option value={item.DICTVALUE}>{item.DESCRIPTION}</Option>
                        }):null}
                      </Select>
                    )}
              </FormItem>
            </Col>
          </Row>

          <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

          	<Col md={12} sm={24}>
          	  <FormItem  label="级别">
          	      {getFieldDecorator('a0511', {
          	        rules: [{ required: false, message: '请选择'}],
                    initialValue: formVals.a0511,
          	        })(
          	        <Select labelInValue placeholder="请选择" style={{ width: '100%' }}>
          	          {dicListByPcode('AE') != undefined?dicListByPcode('AE').map((item,index) => {
          	            return <Option value={item.DICTVALUE}>{item.DESCRIPTION}</Option>
          	          }):null}
          	        </Select>
          	      )}
          	  </FormItem>
          	</Col>

            <Col md={12} sm={24}>
              <FormItem  label="性质类别">
                  {getFieldDecorator('a0514', {
                    rules: [{ required: false, message: '请选择'}],
                    initialValue: formVals.a0514,
                    })(
                      <Select labelInValue placeholder="请选择" style={{ width: '100%' }}>
                        {dicListByPcode('AE') != undefined?dicListByPcode('AE').map((item,index) => {
                          return <Option value={item.DICTVALUE}>{item.DESCRIPTION}</Option>
                        }):null}
                      </Select>
                    )}
              </FormItem>
            </Col>
          </Row>

          <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

          	<Col md={12} sm={24}>
          	  <FormItem  label="所属行业">
          	      {getFieldDecorator('a0517', {
          	        rules: [{ required: false, message: '请选择'}],
                    initialValue: formVals.a0517,
          	        })(
          	        <Select labelInValue placeholder="请选择" style={{ width: '100%' }}>
          	          {dicListByPcode('AE') != undefined?dicListByPcode('AE').map((item,index) => {
          	            return <Option value={item.DICTVALUE}>{item.DESCRIPTION}</Option>
          	          }):null}
          	        </Select>
          	      )}
          	  </FormItem>
          	</Col>
            {/* 免职信息*/}
            <Col md={12} sm={24}>
              <FormItem  label="免职日期">
                  {getFieldDecorator('a0561', {
                    rules: [{ required: false, message: '请选择'}],
                    initialValue: formVals.a0561?moment(formVals.a0561):null,
                    })(
                      <DatePicker  format="YYYY-MM-DD" style={{ width: '100%' }} placeholder="请选择"/>
                    )}
              </FormItem>
            </Col>
          </Row>

          <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

          	<Col md={12} sm={24}>
          	  <FormItem  label="免职变动类别">
          	      {getFieldDecorator('a0567', {
          	        rules: [{ required: false, message: '1-40个字符'}],
                    initialValue: formVals.a0567,
          	        })(
          	        <Select labelInValue placeholder="请选择" style={{ width: '100%' }}>
          	          {dicListByPcode('AE') != undefined?dicListByPcode('AE').map((item,index) => {
          	            return <Option value={item.DICTVALUE}>{item.DESCRIPTION}</Option>
          	          }):null}
          	        </Select>
          	      )}
          	  </FormItem>
          	</Col>

            <Col md={12} sm={24}>
              <FormItem  label="多职务名称描述">
                  {getFieldDecorator('a0565', {
                    rules: [{ required: false, message: '请选择'}],
                    initialValue: formVals.a0565,
                    })(
                      <Input placeholder="1-40个字符" />
                    )}
              </FormItem>
            </Col>
          </Row>

          <Row gutter={{ md: 8, lg: 24, xl: 48 }}>
          	<Col md={12} sm={24}>
                  <Button
                  	size="large"
                  	style={{marginRight: '10px'}}
                  	onClick={()=> {
                  		const { form } = this.props;
          				form.resetFields();
                  		cancelEditJobInfo(spinIndex);
                  	}}>
                  	取消
                 	</Button>
                  <Button size="large" type="primary" htmlType="submit">保存</Button>
              </Col>
          </Row>

			  </Form>
			):(
			<Form  {...formItemLayout}>
			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

			        <Col md={12} sm={24}>
			          <FormItem  label="专业技术职务名称">
			              {getFieldDecorator('a0524')(<span>{formVals.a0301}</span>)}
			          </FormItem>
			        </Col>

					<Col md={12} sm={24}>
			          <FormItem  label="任职方式">
			              {getFieldDecorator('a0547')(<span>{formVals.a0547}</span>)}
			          </FormItem>
			        </Col>

			    </Row>
			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

			        <Col md={12} sm={24}>
			          <FormItem  label="任职状态">
			              {getFieldDecorator('a0554')(<span>{formVals.a0554}</span>)}
			          </FormItem>
			        </Col>
			        <Col md={12} sm={24}>
			          <FormItem  label="专业技术岗位等级">
			              {getFieldDecorator('a0568')(<span>{formVals.a0568}</span>)}
			          </FormItem>
			        </Col>

			    </Row>

			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

					<Col md={12} sm={24}>
			          <FormItem  label="任职变动类别">
			              {getFieldDecorator('a0551')(<span>{formVals.a0551}</span>)}
			          </FormItem>
			        </Col>
			        <Col md={12} sm={24}>
			          <FormItem  label="任职起始日期">
			              {getFieldDecorator('a0544')(<span>{formVals.a0544?moment(formVals.a0544).format('YYYY-MM-DD'):null}</span>,
                    )}
			          </FormItem>
			        </Col>


			    </Row>

			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

			        <Col md={12} sm={24}>
			          <FormItem  label="多职务主次序号">
			              {getFieldDecorator('a0527')(<span>{formVals.a0527}</span>)}
			          </FormItem>
			        </Col>
			        <Col md={12} sm={24}>
			          <FormItem  label="集体内排列顺序">
			              {getFieldDecorator('a0531')(<span>{formVals.a0531}</span>)}
			          </FormItem>
			        </Col>

			    </Row>

			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

			        <Col md={12} sm={24}>
			          <FormItem  label="主管工作">
			              {getFieldDecorator('a0534')(<span>{formVals.a0534}</span>)}
			          </FormItem>
			        </Col>
			        <Col md={12} sm={24}>
			          <FormItem  label="批准文件名称或文号">
			              {getFieldDecorator('a0545')(<span>{formVals.a0545}</span>)}
			          </FormItem>
			        </Col>

			    </Row>
			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

			    	<Col  md={12} sm={24}>
				        <FormItem  label="聘任证书编号">
				            {getFieldDecorator('a0549')(<span>{formVals.a0549}</span>)}
				        </FormItem>
			        </Col>
			        <Col md={12} sm={24}>
			          <FormItem  label="任职预定截止日期">
			              {getFieldDecorator('a0557')(<span>{formVals.a0557?moment(formVals.a0557).format('YYYY-MM-DD'):null}</span>,
                    )}
			          </FormItem>
			        </Col>

			    </Row>
          {/* 任职机构信息*/}
          <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

              <Col md={12} sm={24}>
                <FormItem  label="名称">
                    {getFieldDecorator('a0501_1')(<span>{formVals.a0501_1}</span>)}
                </FormItem>
              </Col>
              <Col md={12} sm={24}>
                <FormItem  label="代码">
                    {getFieldDecorator('a0501_2')(<span>{formVals.a0501_2}</span>)}
                </FormItem>
              </Col>

          </Row>

          <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

              <Col md={12} sm={24}>
                <FormItem  label="所在政区">
                    {getFieldDecorator('a0504')(<span>{formVals.a0504}</span>)}
                </FormItem>
              </Col>
              <Col md={12} sm={24}>
                <FormItem  label="隶属关系">
                    {getFieldDecorator('a0507')(<span>{formVals.a0507}</span>)}
                </FormItem>
              </Col>

          </Row>

          <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

              <Col md={12} sm={24}>
                <FormItem  label="级别">
                    {getFieldDecorator('a0511')(<span>{formVals.a0511}</span>)}
                </FormItem>
              </Col>
              <Col md={12} sm={24}>
                <FormItem  label="性质类别">
                    {getFieldDecorator('a0514')(<span>{formVals.a0514}</span>)}
                </FormItem>
              </Col>

          </Row>

          <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

              <Col md={12} sm={24}>
                <FormItem  label="所属行业">
                    {getFieldDecorator('a0517')(<span>{formVals.a0517}</span>)}
                </FormItem>
              </Col>
              <Col md={12} sm={24}>
                <FormItem  label="免职日期">
                    {getFieldDecorator('a0561')(<span>{formVals.a0561?moment(formVals.a0561).format('YYYY-MM-DD'):null}</span>)}
                </FormItem>
              </Col>

          </Row>

          <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

              <Col md={12} sm={24}>
                <FormItem  label="免职变动类别">
                    {getFieldDecorator('a0567')(<span>{formVals.a0567}</span>)}
                </FormItem>
              </Col>
              <Col md={12} sm={24}>
                <FormItem  label="多职务名称描述">
                    {getFieldDecorator('a0565')(<span>{formVals.a0565}</span>)}
                </FormItem>
              </Col>

          </Row>

			  </Form>
			)}
		</div>


	);
  }

}

export default UpdateForm;
